﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class UIVESTAMM : ViewBase
    {
        

         #region ==ERTNA===========
        public static readonly DependencyProperty ERTNAProperty = DependencyProperty.Register("ERTNA",
            typeof(string), typeof(UIVESTAMM),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnERTNAChanged));
        public string ERTNA
        {
            get
            {
                return (string)GetValue(ERTNAProperty);
            }
            set
            {
                SetValue(ERTNAProperty, value);
            }
        }
        private static void OnERTNAChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVESTAMM;
            if (src != null)
            {
                src.ERTNA = (string)e.NewValue;
            }
        }
        #endregion

        
        #region ==dwVS===========
        public static readonly DependencyProperty dwVSProperty = DependencyProperty.Register("dwVS",
            typeof(DataRow), typeof(UIVESTAMM),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwVSChanged));
        public DataRow dwVS
        {
            get
            {
                return (DataRow)GetValue(dwVSProperty);
            }
            set
            {
                SetValue(dwVSProperty, value);
            }
        }
        private static void OdwVSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVESTAMM;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwVS = row;
            }
        }
        #endregion

        public UIVESTAMM()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return; 
        }
        /// <summary>
        /// SetProd 当前订单
        /// SetData保存所有订单，但是用于展示今日订单
        /// SetEnv保存所有订单
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVS = dwMaster;
            if (dwMaster != null)
            {
                KEY = dwVS["VEVERTNR"].ToString();
            }
            else
            {
                KEY = "";
            }
        }

        public override void LOADBYAUF()
        {
            if (ORDERNUM.Trim().Length == 0)
            { 
                return;
            }
            TBMain.Clear();
            dwData = TBMain.NewRow();
            dwData["VEMANDANT"] = app.Mandant;
            dwData["VEVERTNR"] = ORDERNUM;
            SResult = ((VVESTAMM)MV).QueryVESTAMM(dwData, 1);
            MergeData(SResult, true);
            base.LOADBYAUF();
        }
    }
}
